package A1_回溯;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LC_17电话号码的字母组合 {


    static List<String> result=new ArrayList<>();
    static StringBuilder s=new StringBuilder();
    public static List<String> letterCombinations(String digits) {
        if(digits==null||digits.length()==0)
            return result;
        String[] letterMap={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        backtracking(digits,letterMap,0);
        return result;

    }
    public static void backtracking(String digits, String[] letterMap, int index){
        if(index==digits.length()){
            result.add(s.toString());
            return;
        }
        int digit=Integer.parseInt(String.valueOf(digits.charAt(index)));
        String letter=letterMap[digit];
//        String letter=letterMap[digits.charAt(index)];//取对应字母
        for(int i=0;i<letter.length();i++){
            s.append(letter.charAt(i));
            backtracking(digits,letterMap,index+1);
            s.deleteCharAt(s.length()-1);
        }
    }
    public static void main(String[] args){
//        backtracking(String.valueOf(23),1);
        letterCombinations("23");
    }
}
